package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.PrinterTemplateService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.PrinterTemplateAddVO;
import com.junzhiit.nengji.cms.web.vo.PrinterTemplateEditVO;
import com.junzhiit.nengji.cms.web.vo.PrinterTemplateVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

@RestController
@RequestMapping("/printer/template")
public class PrinterTemplateController extends BaseController{
	
	@Autowired
	private PrinterTemplateService printerTemplateService;
	
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findPageAll(PrinterTemplateVO printerTemplateVO,DataTablesParamVO dtp){
		return printerTemplateService.findPageAll(printerTemplateVO,dtp);
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResultVO findById(@PathVariable String id){
		AssertUtil.notBlank(id, "id is required");
		return printerTemplateService.findById(id);
	}
	
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(PrinterTemplateVO printerTemplateVO){
		return printerTemplateService.getAll(printerTemplateVO);
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(PrinterTemplateAddVO printerTemplateAddVO){
		AssertUtil.notBlank(printerTemplateAddVO.getName(), "name is required");
		AssertUtil.notBlank(printerTemplateAddVO.getContent(), "content is required");
		return printerTemplateService.add(printerTemplateAddVO);
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResultVO edit(@PathVariable String id,PrinterTemplateEditVO printerTemplateEditVO){
		AssertUtil.notBlank(printerTemplateEditVO.getName(), "name is required");
		AssertUtil.notBlank(printerTemplateEditVO.getContent(), "content is required");
		return printerTemplateService.edit(id,printerTemplateEditVO);
	}
	
	@RequestMapping(value="/use/{id}",method=RequestMethod.GET)
	public ResultVO getUseCount(@PathVariable String id,PrinterTemplateVO printerTemplateVO){
		return printerTemplateService.getUseCount(id,printerTemplateVO);
	} 
	
	@RequestMapping(value="/del/{id}")
	public ResultVO updateToDelete(@PathVariable String id){
		return printerTemplateService.updateToDelete(id);
	}
}
